# Project III
# data was imported and filtered from Our World in Data website
# https://ourworldindata.org/suicide#suicide-is-a-leading-cause-of-death-especially-in-young-people
# and from Kaggle
# https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016
import pandas as pd
import os
import matplotlib.pyplot as plt
import numpy as np
import plotly.express as px
#reading csv files
death = pd.read_csv('deaths.csv', index_col=0, encoding = "ISO-8859-1")
suicide = pd.read_csv('suicide.csv', index_col=0, encoding = "ISO-8859-1")
# displaying data in deaths dataset
# detaset is between 1900 and 2017, after filtering by years between 2000
# and 2017 we have 4290 rows and 34 columns
death.shape
# displaying suicide dataset
# dataset is between 1985 and 2016, after filtering by years between 2000
# and 2016 we have 16168 rows with
suicide.shape
# 2016
suicide_2016 = suicide[suicide.year == 2016]
suicide_2016
# cleaning unused data: deleting columns gdp_for_year ($), gdp_per_capita ($) and generation
del suicide_2016[' gdp_for_year ($) '], suicide_2016['gdp_per_capita ($)'], suicide_2016['generation']
suicide_2016
# suicide_2016
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'suicides_no'].sum()
aus = suicide_2016.loc[suicide['country'] == 'Austria', 'suicides_no'].sum()
cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'suicides_no'].sum()
cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'suicides_no'].sum()
cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'suicides_no'].sum()
gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'suicides_no'].sum()
hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'suicides_no'].sum()
ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'suicides_no'].sum()
lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'suicides_no'].sum()
mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'suicides_no'].sum()
mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'suicides_no'].sum()
net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'suicides_no'].sum()
qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'suicides_no'].sum()
rom = suicide_2016.loc[suicide['country'] == 'Romania', 'suicides_no'].sum()
swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'suicides_no'].sum()
thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'suicides_no'].sum()
#country = suicide_2016['country'].unique()
total_num = [ 'Armenia', arm], [ 'Austria', aus], ['Croatia', cro], ['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre], ['Hungary', hun], ['Iceland', ice], ['Lithuania', lit], ['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net], ['Qatar', qat], ['Romania', rom], ['Sweden', swe], ['Thailand', thai]
total_2016 = pd.DataFrame(total_num, columns = ['Country', 'Total'])
tot_2016 = total_2016.sort_values(by='Total', ascending=False)
tt_2016 = tot_2016.head()
tt_2016
import plotly.graph_objects as go
labels = tt_2016.Country
values = tt_2016.Total
fig = go.Figure(data = [go.Pie(labels = labels, values = values, pull =[0,0,0,0,0.2], title = 'The Total Number of Suicides in 2016')])
fig.show()
fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 19
fig_size[1] = 7
plt.rcParams["figure.figsize"] = fig_size
plt.title("Total number of suicides by country in 2016")
plt.scatter(tot_country['Country'], tot_country['Total N'], s=150)
plt.show()
suicide_2016['Percent'] = suicide_2016.suicides_no/suicide_2016.population
suicide_2016.sort_values(by='Percent', ascending=False)
# calculating percentage for every country
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'Percent'].sum()
aus = suicide_2016.loc[suicide['country'] == 'Austria', 'Percent'].sum()
cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'Percent'].sum()
cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'Percent'].sum()
cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'Percent'].sum()
gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'Percent'].sum()
hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'Percent'].sum()
ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'Percent'].sum()
lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'Percent'].sum()
mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'Percent'].sum()
mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'Percent'].sum()
net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'Percent'].sum()
qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'Percent'].sum()
rom = suicide_2016.loc[suicide['country'] == 'Romania', 'Percent'].sum()
swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'Percent'].sum()
thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'Percent'].sum()
p_total_num = [ 'Armenia', arm], [ 'Austria', aus], ['Croatia', cro], ['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre], ['Hungary', hun], ['Iceland', ice], ['Lithuania', lit], ['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net], ['Qatar', qat], ['Romania', rom], ['Sweden', swe], ['Thailand', thai]
p_total_2016 = pd.DataFrame(p_total_num, columns = ['Country', 'Percent'])
p_tot_2016 = p_total_2016.sort_values(by='Percent', ascending=False)
p_perc_tt_2016 = p_tot_2016.head()
p_perc_tt_2016
import plotly.graph_objects as go
labels = p_perc_tt_2016.Country
values = p_perc_tt_2016.Percent
fig = go.Figure(data = [go.Pie(labels = labels, values = values, pull =[0,0,0,0,0.2], title = 'The Highest Percentage of Suicides by Country in 2016')])
fig.show()
import plotly.graph_objects as go
from plotly.subplots import make_subplots
labels_1 = tt_2016.Country
labels_2 = p_perc_tt_2016.Country
# Create subplots: use 'domain' type for Pie subplot
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels_1, values=tt_2016.Total, name="The Total Number of Suicides in 2016"),
1, 1)
fig.add_trace(go.Pie(labels=labels_2, values=p_perc_tt_2016.Percent, name="Total Highest Percentage of Suicides in 2016"),
1, 2)
# Use `hole` to create a donut-like pie chart
fig.update_traces(hole=.4, hoverinfo="label+percent+name")
fig.update_layout(
title_text="Total Number of Suicides vs Total Highest Percentage of Suicides in 2016",
# Add annotations in the center of the donut pies.
annotations=[dict(text='TNS', x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text='THPS', x=0.82, y=0.5, font_size=20, showarrow=False)])
fig.show()
# 2015
suicide_2015 = suicide[suicide.year == 2015]
del suicide_2015[' gdp_for_year ($) '], suicide_2015['gdp_per_capita ($)'], suicide_2015['generation'], suicide_2015['year']
suicide_2015.sort_values(by='population', ascending=False)
# The highest number of suicides in by sex
tot_2015 = suicide_2015.groupby(['country', 'sex'])['suicides_no'].sum().reset_index()
tot_2015.sort_values(by='suicides_no', ascending=False)
# The total highest number of suicides by country (male+female)
tot_2015 = suicide_2015.groupby(['country'])['suicides_no'].sum().reset_index()
tot_suicide_2015 = tot_2015.sort_values(by = 'suicides_no', ascending=False)
tot_suicide_2015
suicide_2015['Percent'] = suicide_2015.suicides_no/suicide_2015.population
top5_2015_bypercent = suicide_2015.sort_values(by='Percent', ascending=False)
top_5_2015_bypercent = top5_2015_bypercent.head()
top_5_2015_bypercent
import plotly.graph_objects as go
from plotly.subplots import make_subplots
labels_1 = ['United States','Russian Federation','Japan','Republic of Korea', 'Brazil']
labels_2 = ['Republic of Korea','Slovenia','Hungary','Lithuania', 'Serbia']
# Create subplots: use 'domain' type for Pie subplot
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels_1, values=top_5_2015_bypercent.suicides_no, name="Total Suicide Numbers in 2015"),1, 1)
fig.add_trace(go.Pie(labels=labels_2, values=top_5_2015_bypercent.Percent, name="Total Suicides Percentage in 2015"),1, 2)
# Use `hole` to create a donut-like pie chart
fig.update_traces(hole=.4, hoverinfo="label+percent+name")
fig.update_layout(
title_text="Total Suicide Number vs Total Suicide Percentage in 2015",
# Add annotations in the center of the donut pies.
annotations=[dict(text='TSN', x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text='TSP', x=0.82, y=0.5, font_size=20, showarrow=False)])
fig.show()
import plotly.express as px
tips = px.data.tips()
fig = px.bar(tips, y = tot_2015.country, x = tot_2015.suicides_no, orientation='h', title ='Total number \
of suicides in 2015')
fig.show()
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(
y=tot_2015.country,
x=tot_2015.suicides_no,
name='Male',
orientation='h',
marker=dict(
color='rgba(246, 78, 139, 0.6)',
line=dict(color='rgba(246, 78, 139, 1.0)', width=3)
)
))
fig.add_trace(go.Bar(
y=tot_2015.country,
x=tot_2015.suicides_no,
name='Female',
orientation='h',
marker=dict(
color='rgba(58, 71, 80, 0.6)',
line=dict(color='rgba(58, 71, 80, 1.0)', width=3)
)
))
fig.update_layout(barmode='stack', title_text = 'Total number of suicides by sex in 2015')
fig.show()
import plotly.graph_objects as go
fig = go.Figure(data = [go.Bar(name = 'Male', x = suicide_2016.country, y=suicide_2016.Percent),
go.Bar(name = 'Female', x = suicide_2016.country, y=suicide_2016.Percent)])
fig.update_layout(barmode='stack', title_text ='The Percentage (ratio) number of \
suicides and population by gender and by country in 2016')
fig.show()
import plotly.graph_objects as go
fig = go.Figure(data = [go.Bar(name = 'Male', x = suicide_2016.country, y=suicide_2016.suicides_no),
go.Bar(name = 'Female', x = suicide_2016.country, y=suicide_2016.suicides_no)])
fig.update_layout(barmode='stack', title_text ='The number of suicides by gender and by country in 2016')
fig.show()
# creating a variable for every (16) countries for future analysis
suicide_2016_Armenia = suicide_2016[suicide_2016.country == "Armenia"]
suicide_2016_Austria = suicide_2016[suicide_2016.country == "Austria"]
suicide_2016_Croatia = suicide_2016[suicide_2016.country == "Croatia"]
suicide_2016_Cyprus = suicide_2016[suicide_2016.country == "Cyprus"]
suicide_2016_Czech = suicide_2016[suicide_2016.country == "Czech Republic"]
suicide_2016_Grenada = suicide_2016[suicide_2016.country == "Grenada"]
suicide_2016_Hungary = suicide_2016[suicide_2016.country == "Hungary"]
suicide_2016_Iceland = suicide_2016[suicide_2016.country == "Iceland"]
suicide_2016_Lithuania = suicide_2016[suicide_2016.country == "Lithuania"]
suicide_2016_Mauritius = suicide_2016[suicide_2016.country == "Mauritius"]
suicide_2016_Mongolia = suicide_2016[suicide_2016.country == "Mongolia"]
suicide_2016_Netherlands = suicide_2016[suicide_2016.country == "Netherlands"]
suicide_2016_Qatar = suicide_2016[suicide_2016.country == "Qatar"]
suicide_2016_Romania = suicide_2016[suicide_2016.country == "Romania"]
suicide_2016_Sweden = suicide_2016[suicide_2016.country == "Sweden"]
suicide_2016_Thailand = suicide_2016[suicide_2016.country == "Thailand"]
suicide_bar = suicide_2016_Armenia.plot.bar(
x="age",
y="suicides_no",
title="Suicide number by age in Armenia",
figsize=(15,5), stacked=True,
colormap = "viridis")
suicide_bar_1 = suicide_2016_Armenia.plot.bar(
x="sex",
y="suicides_no",
title="Suicide number by sex in Armenia",figsize=(15,5),
stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Austria.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Austria",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Austria.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Austria",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Croatia.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Croatia",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Croatia.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Croatia",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Cyprus.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Cyprus",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Cyprus.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Cyprus",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Czech.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Czech Republic",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Czech.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Czech Republic",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Grenada.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Grenada",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Grenada.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Grenada",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Hungary.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Hungary",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Hungary.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Hungary",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Lithuania.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Lithuania",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Lithuania.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Lithuania",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Mauritius.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Mauritius",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Mauritius.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Mauritius",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Mongolia.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Mongolia",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Mongolia.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Mongolia",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Netherlands.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Netherlands",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Netherlands.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Netherlands",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Qatar.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Qatar",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Qatar.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Qatar",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Romania.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Romania",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Romania.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Romania",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Sweden.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Sweden",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Sweden.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Sweden",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Thailand.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Thailand",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Thailand.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Thailand",
figsize=(15,5), stacked=True,colormap = "plasma")
suicide_bar = suicide_2016_Iceland.plot.bar(
x="age", y="suicides_no",
title="Suicide number by age in Iceland",
figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Iceland.plot.bar(
x="sex", y="suicides_no",
title="Suicide number by sex in Iceland",
figsize=(15,5), stacked=True,colormap = "plasma")
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'suicides_no'].sum()
print ("%d people commited suicide in Armenia, 2016" %arm)
aus = suicide_2016.loc[suicide['country'] == 'Austria', 'suicides_no'].sum()
print ("%d people commited suicide in Austria, 2016" %aus)
cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'suicides_no'].sum()
print ("%d people commited suicide in Croatia, 2016" %cro)
cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'suicides_no'].sum()
print ("%d people commited suicide in Cyprus, 2016" %cyp)
cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'suicides_no'].sum()
print ("%d people commited suicide in Czech Republic, 2016" %cze)
gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'suicides_no'].sum()
print ("%d people commited suicide in Grenada, 2016" %gre)
hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'suicides_no'].sum()
print ("%d people commited suicide in Hungary, 2016" %hun)
ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'suicides_no'].sum()
print ("%d people commited suicide in Iceland, 2016" %ice)
lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'suicides_no'].sum()
print ("%d people commited suicide in Lithuania in 2016" %lit)
mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'suicides_no'].sum()
print ("%d people commited suicide in Mauritius in 2016" %mau)
mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'suicides_no'].sum()
print ("%d people commited suicide in Mongolia, 2016" %mon)
net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'suicides_no'].sum()
print ("%d people commited suicide in Netherlands, 2016" %net)
qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'suicides_no'].sum()
print ("%d people commited suicide in Qatar, 2016" %qat)
rom = suicide_2016.loc[suicide['country'] == 'Romania', 'suicides_no'].sum()
print ("%d people commited suicide in Romania, 2016" %rom)
swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'suicides_no'].sum()
print ("%d people commited suicide in Sweden, 2016" %swe)
thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'suicides_no'].sum()
print ("%d people commited suicide in Thailand, 2016" %thai)
totoal_bycountry =[['Armenia', arm], ['Austria', aus], ['Croatia', cro],
['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre],
['Hungary', hun], ['Iceland', ice], ['Lithuania', lit],
['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net],
['Qatar', qat], ['Romania', rom], ['Sweden', swe],
['Thailand', thai]]
tot_country = pd.DataFrame(totoal_bycountry,columns = ['Country', 'Total N'])
tot_country.sort_values(by='Total N', ascending=False)
suicide_bar = tot_country.plot.bar(
x="Country", y="Total N",
title="Total number committed suicides by country",
figsize=(15,5), stacked=True,colormap = "summer")
# Deaths dataset
death
death_2017 = death[death.Year == 2017]
death_2017
# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np
death_2017_clean = death_2017.replace(np.nan, ' ', regex=True)
death_2017_clean
del death_2017_clean['Year']
death_2017_clean
# World 2017
import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=death_2017_clean.iloc[232],
y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)'
],
orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2017')
fig.show()
import plotly.graph_objects as go
fig_2 = go.Figure(go.Bar(
x=death_2017_clean.iloc[232],
y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
],
orientation='h'))
fig_2.update_layout(title= 'Death causes in the World, 2017')
fig_2.show()
death_16 = death[death.Year == 2016]
# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np
death_2016 = death_16.replace(np.nan, ' ', regex=True)
# removing Year column
del death_2016['Year']
death_2016
#World 2016
import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=death_2016.iloc[232],
y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)'
],
orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2016')
fig.show()
import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=death_2016.iloc[232],
y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
],
orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2016')
fig.show()
death_00 = death[death.Year == 2000]
# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np
death_2000 = death_00.replace(np.nan, ' ', regex=True)
# removing Year column
del death_2000['Year']
death_2000
# World 2000
import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=death_2000.iloc[235],
y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)',
],
orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2000')
fig.show()
import plotly.graph_objects as go
fig = go.Figure(go.Bar(
x=death_2000.iloc[235],
y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
],
orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2000')
fig.show()
import plotly.graph_objects as go
labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)',
'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
]
values = death_2017_clean.iloc[222]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2017")
fig.show()
import plotly.graph_objects as go
labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)',
'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
]
values = death_2016.iloc[232]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2016")
fig.show()
import plotly.graph_objects as go
labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)',
'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)',
'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)',
'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)',
'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)',
'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)',
'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)',
'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)',
'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)',
'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
]
values = death_2000.iloc[235]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2000")
fig.show()